$.fn.searchStringWidget = function(options) {
    var $this = this;
    options = options || {};
    options.iconUrl = options.iconUrl || './images/';
    $this._init = function() {
    };

    $this._bindEvents = function() {
        $this.autocomplete({minLength:0,source:function(request, response) {

            var tag_dl = ',';

            $.ajax(
                    {url:"ajax/complete",
                        dataType:"json",
                        data:{maxRows:12,q:request.term},
                        success:function(data) {
                            response($.map(data, function(item) {
                                var dl = ',';
                                var name = item.name;

                                return {label: name + dl,
                                    value:name + dl};
                            }));
                        }});
        },
            focus:function() {
                return false;
            },
            search:function() {
                var term = $this.extractLast(this.value);
                if (term.length < 2) {
                    return false;
                }
            },
            select:function(event, ui) {
                var terms = $this.split(this.value);
                terms.pop();
                terms.push(ui.item.value);
                terms.push("");
                this.value = terms.join(" ");
                return false;
            }});
    };

    $this.split = function(val) {
        return val.split(/\s{1,}/);
    };
    $this.extractLast = function(term) {
        return $this.split(term).pop();
    };
    $this._init();
    $this._bindEvents();
    return $(this);
};
